/*=====================================================
Critical Links
Auto Configuration Server

Authors:
	Rui Eduardo Gouveia Gil - r-gil@critical-links.com

Date: 2010
Version 0.1
=======================================================*/
#ifndef __DISKFILE_H__
#define __DISKFILE_H__

#include <map>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/thread/once.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/shared_array.hpp>
#include <pion/net/WebServer.hpp>
#include <pion/net/HTTPTypes.hpp>
#include <boost/functional/hash.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <rgcpp/exceptions/RuntimeException.h>

namespace acs
{

class DiskFile
{
	private:
		std::string mimeType;
		std::time_t lastModified;
		std::streamsize fileSize;
		std::string lastModifiedString;
		boost::filesystem::path filePath;
		boost::shared_array<char> fileContent;

	public:
		DiskFile();
		DiskFile(const boost::filesystem::path& path, char* content, unsigned long size, std::time_t modified, const std::string& mime);
		DiskFile(const DiskFile& f);

		void read();
		void update();
		bool checkUpdated();

		const boost::filesystem::path& getFilePath() const;
		char* getFileContent();
		bool hasFileContent() const;
		unsigned long getFileSize() const;
		std::time_t getLastModified() const;
		const std::string& getLastModifiedString() const;
		const std::string& getMimeType() const;

		void setFilePath(const boost::filesystem::path& p);
		void appendFilePath(const std::string& p);
		void setMimeType(const std::string& mimeType);
		void resetFileContent(unsigned long n = 0);
};

}

#endif
